package com.sc.nft.dao;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.TaskPlanRecordVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.TaskPlan;
import com.sc.nft.mapper.TaskPlanMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 用户任务进度表(sc_task_plan)数据DAO
 *
 * @author 张翔宇
 * @since 2023-03-29 11:14:52
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class TaskPlanDao extends ServiceImpl<TaskPlanMapper, TaskPlan> {

    //查询用户当天完成任务数量
    public Integer selectUserTaskFinishCount(Long userId,Long taskId, Date taskDate) {
        LambdaQueryWrapper<TaskPlan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskPlan::getUserId, userId);
        wrapper.eq(TaskPlan::getTaskId, taskId);
        wrapper.eq(TaskPlan::getStatus, true);
        wrapper.ge(TaskPlan::getTaskDate, DateUtil.formatDate(taskDate));
        return count(wrapper);
    }

    //查询进行中任务
    public TaskPlan selectUserTaskPlan(Long userId,Long taskId, Date taskDate) {
        LambdaQueryWrapper<TaskPlan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskPlan::getUserId, userId);
        wrapper.eq(TaskPlan::getTaskId, taskId);
        wrapper.eq(TaskPlan::getStatus, false);
        wrapper.ge(TaskPlan::getTaskDate, DateUtil.formatDate(taskDate));
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Page<TaskPlanRecordVO> pageAdmin(Long userId, List<Long> taskIdList, Date startTime, Date endTime, int pageNo, int pageSize){
        return baseMapper.pageAdmin(new Page<>(pageNo, pageSize), userId, taskIdList, startTime, endTime);
    }


}